import path from "path"
export function isNull(data) {
    if (!data) return true;
    if (JSON.stringify(data) == "{}") return true;
    if (JSON.stringify(data) == "{}") return true
    return false
}
export let generateMenus = (routes, basePath = "") => {
    let result = [];
    routes.forEach((item, index) => {
        if (isNull(item.meta) && isNull(item.children)) return;
        if (isNull(item.meta) && !isNull(item.children)) {
            result.push(...generateMenus(item.children))
            return;
        }
        let routePath = path.resolve(basePath, item.path);
        let route = result.find((m, i) => { m.path == routePath });
        if (!route) {
            route = {
                ...item,
                path: routePath,
                children: []
            }
            if (route.meta.title && route.meta.icon) {
                result.push(route)
            }
        }
        if (item.children) {
            route.children.push(...generateMenus(item.children, route.path))
        }

    })
    return result
}